package com.sunny.design.template.jdbc.dao;

import com.sunny.design.template.jdbc.JdbcTemplate;
import com.sunny.design.template.jdbc.Member;
import com.sunny.design.template.jdbc.RowMapper;

import javax.sql.DataSource;
import java.util.List;

/**
 * @author Sunny
 * @date 2020/1/9 23:23
 */
public class MemberDao extends JdbcTemplate {

    public MemberDao(DataSource dataSource) {
        super(dataSource);
    }

    public List<?> selectAll() {
        String sql = "select * from t_member";
        return super.executeQuery(sql, (RowMapper<Member>) (rs, rowNum) -> {
            //参数过多可以用原型模式
            Member member = new Member();
            member.setName(rs.getString("username"));
            member.setAddr(rs.getString("addr"));
            member.setAge(rs.getInt("age"));
            return member;
        }, null);
    }
}
